<template>
  <div class="app-container">

    <CommonTable ref="commonTable" :qo="qo" :baba="this" :need-load-dict-type="['system_file_tag']">
      <!-- 查询参数 -->
      <template slot="filterItems">
        <el-form-item label="关键字" prop="keyword">
          <el-input v-model.trim="qo.keyword" clearable />
        </el-form-item>
        <el-form-item label="文件用途" prop="fileTag">
          <el-select v-model="qo.fileTag" clearable>
            <el-option v-for="item in this.$store.getters.dictSelectData.system_file_tag" :key="item.value" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
      </template>
      <!-- 列表头 -->
      <template slot="column">
        <el-table-column type="selection" width="55" />
        <el-table-column label="文件名称" prop="fileName" />
        <el-table-column label="文件类型" prop="fileType" width="80" />
        <el-table-column label="MIME_TYPE" prop="mimeType" width="200" />
        <el-table-column label="文件大小" width="100">
          <template slot-scope="{row}">
            {{ formatFileSize(row) }}
          </template>
        </el-table-column>
        <el-table-column label="文件用途">
          <template slot-scope="{row}">
            <el-tag type="success" effect="light">{{ 'system_file_tag'|transferDictValue(row.fileTag) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="存储路径" prop="filePath" />
        <el-table-column label="上传用户" prop="nickname" width="100" />
        <el-table-column label="上传时间" prop="uploadDate" />
      </template>
    </CommonTable>
  </div>
</template>
<script>
import { list, download, downloadZip } from '@/api/system/file'
import { formatBytes } from '@/utils/index'
import CommonTable from '@/components/CommonTable'
export default {
  name: 'File',
  components: { CommonTable },
  data() {
    return {
      qo: { keyword: '', fileTag: '' }
    }
  },
  created() {
  },
  methods: {
    getData(qoPro) {
      return list(qoPro)
    },
    formatFileSize(row) {
      return formatBytes(row.fileSize, 2)
    },
    download(row) {
      download(row.id)
    },
    downloadZip() {
      this.$refs.commonTable.getSelectedRowIds().then(ids => { downloadZip(ids) })
    }
  }
}
</script>
